#ifndef __BSP_JL_H__
#define __BSP_JL_H__


#include "config.h"
//#include <stdint.h>

#include "hc32_ddl.h"

#if(JL_CHIP == HT7136)

/** @defgroup BLE_CTRL definition
 * @{
 */
#define BSP_JL_RST_PORT      (PortH)     /* OUTPUT */
#define BSP_JL_RST_PIN       (Pin02)
#define BSP_JL_SLEEP_PORT    (PortA)     /* OUTPUT */
#define BSP_JL_SLEEP_PIN     (Pin00)

#define BSP_JL_IRQ_PORT      (PortC)     /* INPUT */
#define BSP_JL_IRQ_PIN       (Pin11)

#define JlRstOn()         (PORT_ResetBits(BSP_JL_RST_PORT, BSP_JL_RST_PIN))
#define JlRstOff()        (PORT_SetBits(BSP_JL_RST_PORT, BSP_JL_RST_PIN))
#define JlSleepOff()      (PORT_ResetBits(BSP_JL_SLEEP_PORT, BSP_JL_SLEEP_PIN))
#define JSleepOn()        (PORT_SetBits(BSP_JL_SLEEP_PORT, BSP_JL_SLEEP_PIN))

#define JlIrqInLow()        (PORT_GetBit(BSP_JL_IRQ_PORT,BSP_JL_IRQ_PIN) == Reset)
#define JlIrqInHigh()       (PORT_GetBit(BSP_JL_IRQ_PORT,BSP_JL_IRQ_PIN) == Set)


#define BSP_JL_IRQ_EXIT      ExtiCh11
#define BSP_JL_IRQ_EIRQ      INT_PORT_EIRQ11

/**
 * @}
 */


/** @defgroup MAIN TO GL SPI Configure definition
 * @{
 */
/* SPI_SCK Port/Pin definition */
#define JL_SPI_SCK_PORT                    (PortC)
#define JL_SPI_SCK_PIN                     (Pin02)
#define JL_SPI_SCK_FUNC                    (Func_Spi1_Sck)

/* SPI_NSS Port/Pin definition */
#define JL_SPI_NSS_PORT                    (PortC)
#define JL_SPI_NSS_PIN                     (Pin03)
#define JlSpiNssOutHigh()                   (PORT_SetBits(JL_SPI_NSS_PORT, JL_SPI_NSS_PIN))
#define JlSpiNssOutLow()                    (PORT_ResetBits(JL_SPI_NSS_PORT, JL_SPI_NSS_PIN))

/* SPI_MOSI Port/Pin definition */
#define JL_SPI_MOSI_PORT                   (PortC)
#define JL_SPI_MOSI_PIN                    (Pin01)
#define JL_SPI_MOSI_FUNC                   (Func_Spi1_Mosi)

/* SPI_MISO Port/Pin definition */
#define JL_SPI_MISO_PORT                   (PortC)
#define JL_SPI_MISO_PIN                    (Pin00)
#define JL_SPI_MISO_FUNC                   (Func_Spi1_Miso)

/* SPI unit and clock definition */
#define JL_SPI_UNIT                        (M4_SPI1)
#define JL_SPI_UNIT_CLOCK                  (PWC_FCG1_PERIPH_SPI1)

/**
 * @}
 */
#elif(JL_CHIP == HT7627S)

/** @defgroup BLE_CTRL definition
 * @{
 */
#define BSP_JL_RST_PORT      (PortH)     /* OUTPUT */
#define BSP_JL_RST_PIN       (Pin02)
#define BSP_JL_SLEEP_PORT    (PortA)     /* OUTPUT */
#define BSP_JL_SLEEP_PIN     (Pin00)

#define BSP_JL_IRQ_PORT      (PortC)     /* INPUT */
#define BSP_JL_IRQ_PIN       (Pin11)

#define JlRstOn()         (PORT_ResetBits(BSP_JL_RST_PORT, BSP_JL_RST_PIN))
#define JlRstOff()        (PORT_SetBits(BSP_JL_RST_PORT, BSP_JL_RST_PIN))
#define JlSleepOff()      (PORT_ResetBits(BSP_JL_SLEEP_PORT, BSP_JL_SLEEP_PIN))
#define JSleepOn()        (PORT_SetBits(BSP_JL_SLEEP_PORT, BSP_JL_SLEEP_PIN))

#define JlIrqInLow()        (PORT_GetBit(BSP_JL_IRQ_PORT,BSP_JL_IRQ_PIN) == Reset)
#define JlIrqInHigh()       (PORT_GetBit(BSP_JL_IRQ_PORT,BSP_JL_IRQ_PIN) == Set)


#define BSP_JL_IRQ_EXIT      ExtiCh11
#define BSP_JL_IRQ_EIRQ      INT_PORT_EIRQ11

/**
 * @}
 */


/** @defgroup MAIN TO GL SPI Configure definition
 * @{
 */
/* SPI_SCK Port/Pin definition */
#define JL_SPI_SCK_PORT                    (PortC)
#define JL_SPI_SCK_PIN                     (Pin01)
#define JL_SPI_SCK_FUNC                    (Func_Spi1_Sck)

/* SPI_NSS Port/Pin definition */
#define JL_SPI_NSS_PORT                    (PortC)
#define JL_SPI_NSS_PIN                     (Pin00)
#define JlSpiNssOutHigh()                   (PORT_SetBits(JL_SPI_NSS_PORT, JL_SPI_NSS_PIN))
#define JlSpiNssOutLow()                    (PORT_ResetBits(JL_SPI_NSS_PORT, JL_SPI_NSS_PIN))

/* SPI_MOSI Port/Pin definition */
#define JL_SPI_MOSI_PORT                   (PortC)
#define JL_SPI_MOSI_PIN                    (Pin03)
#define JL_SPI_MOSI_FUNC                   (Func_Spi1_Mosi)

/* SPI_MISO Port/Pin definition */
#define JL_SPI_MISO_PORT                   (PortC)
#define JL_SPI_MISO_PIN                    (Pin02)
#define JL_SPI_MISO_FUNC                   (Func_Spi1_Miso)

/* SPI unit and clock definition */
#define JL_SPI_UNIT                        (M4_SPI1)
#define JL_SPI_UNIT_CLOCK                  (PWC_FCG1_PERIPH_SPI1)

/**
 * @}
 */

#endif

void BspJlInit(void);
uint8 BspJlSpiWriteByte(uint8 dat);
uint8 BspJlSpiReadByte(void);






#endif
